package com.polaris.live.adapter.party

import android.view.View
import com.bumptech.glide.Glide
import com.polaris.live.R
import com.polaris.live.R.drawable
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterMemberRoomInfoBinding
import com.polaris.live.im.sfs.bean.live.ext.UserBasicVo
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.image.normal
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * RoomInfoMemberAdapter 成员
 *
 * @author Created by 天晴 on 2024/9/25/004 12:03
 */
class RoomInfoMemberAdapter : BaseBindingAdapter<AdapterMemberRoomInfoBinding, UserBasicVo>() {

    init {
        addChildClickViewIds(R.id.remove_member, R.id.av_fv)
    }

    private var role = member
    private var anchor = false
    override fun convert(holder: VBViewHolder<AdapterMemberRoomInfoBinding>, item: UserBasicVo) {
        holder.vb.apply {
            Glide.with(context).load(ImageUtils.imgPathSmall(item.avatar)).normal().into(followItemHead)
            nickname.text = item.nickname
            avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(item.avatarFrame))
            if (item.country?.isBlank() == true) {
                cvCountry.visibility = View.GONE
            } else {
                cvCountry.visibility = View.VISIBLE
                cvCountry.setCountry(item.country)
            }
            vipView.setVipLevel(item.vipLevel)
            sexView.setSexAndAge(item.sex, item.birthday)
            languageView.setLanguage(item.secondLanguage)
            myLevel.setRichsLevel(item.richs)
            myLevel2.setCharmsLevel(item.charms)
            idView.setId(item)
            llFlag.setLabel(item.label)
            when (role) {
                administrator -> {
                    ivOfficial.setImageResource(drawable.ic_rank_indentity_administrator)
                }

                member -> {
                    ivOfficial.setImageResource(drawable.ic_rank_indentity_audience)
                    if (anchor) {
                        removeMember.visibility = View.VISIBLE
                    }

                }

                owner -> {
                    ivOfficial.setImageResource(drawable.ic_rank_room)
                }
            }
        }
    }

    fun setRole(role: Int) {
        this.role = role
        if (data.isNotEmpty()) {
            notifyDataSetChanged()
        }
    }

    fun setAnchor(anchor: Boolean) {
        this.anchor = anchor
        if (data.isNotEmpty()) {
            notifyDataSetChanged()
        }
    }

    companion object {

        const val administrator = 0 //管理员
        const val member = 1   //成员
        const val owner = 2    //房主

    }

}